home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH05 / PGM5_6.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-09  |  2.4 KB  |  128 lines

  1. ; Arrays of Structures
  2. ;
  3. ; Randall Hyde
  4.  
  5.  
  6. dseg        segment    para public 'data'
  7.  
  8.  
  9. ; A structure that defines an (x,y) coordinate.
  10. ; Note that the Point data type requires four bytes.
  11.  
  12. Point        struct
  13. X        word    ?
  14. Y        word    ?
  15. Point        ends
  16.  
  17.  
  18.  
  19. ; An uninitialized point:
  20.  
  21. Pt1        Point    {}
  22.  
  23. ; An initialized point:
  24.  
  25. Pt2        Point    {12,45}
  26.  
  27.  
  28. ; A one-dimensional array of uninitialized points:
  29.  
  30. PtAry1        Point    16 dup ({})    ;Note the "{}" inside the parens.
  31.  
  32.  
  33. ; A one-dimensional array of points, all initialized to the origin.
  34.  
  35. PtAry1i        Point    16 dup ({0,0})
  36.  
  37.  
  38. ; A two-dimensional array of points:
  39.  
  40. PtAry2        Point    4 dup (4 dup ({}))
  41.  
  42.  
  43. ; A three-dimensional array of points, all initialized to the origin.
  44.  
  45. PtAry3        Point    2 dup (3 dup (4 dup ({0,0})))
  46.  
  47.  
  48.  
  49. ; A one-dimensional array of points, all initialized to different values:
  50.  
  51. iPtAry        Point    {0,0}, {1,2}, {3,4}, {5,6}
  52.  
  53.  
  54. ; Some indices for the arrays:
  55.  
  56. J        word    1
  57. K        word    2
  58. L        word    3
  59.  
  60. dseg        ends
  61.  
  62.  
  63.  
  64.  
  65.  
  66. ; The following program demonstrates how to access each of the above
  67. ; variables.
  68.  
  69. cseg        segment    para public 'code'
  70.         assume    cs:cseg, ds:dseg
  71.  
  72. Main        proc
  73.         mov    ax, dseg    ;These statements are provided by
  74.         mov    ds, ax        ; shell.asm to initialize the
  75.         mov    es, ax        ; segment register.
  76.  
  77. ; PtAry1[J] := iPtAry[J]
  78.  
  79.         mov    bx, J        ;Index := J*4 since there are four
  80.         add    bx, bx        ; bytes per array element (each
  81.         add    bx, bx        ; element contains two words).
  82.  
  83.         mov    ax, iPtAry[bx].X
  84.         mov    PtAry1[bx].X, ax
  85.  
  86.         mov    ax, iPtAry[bx].Y
  87.         mov    PtAry1[bx].Y, ax
  88.  
  89. ; CX := PtAry2[K,L].X;  DX := PtAry2[K,L].Y
  90.  
  91.         mov    bx, K        ;Index := (K*4 + J)*4
  92.         add    bx, bx        ;K*2
  93.         add    bx, bx        ;K*4
  94.         add    bx, J        ;K*4 + J
  95.         add    bx, bx        ;(K*4 + J)*2
  96.         add    bx, bx        ;(K*4 + J)*4
  97.  
  98.         mov    cx, PtAry2[bx].X
  99.         mov    dx, PtAry2[bx].Y
  100.  
  101. ; PtAry3[j,k,l].X := 0
  102.  
  103.         mov    ax, j        ;Index := ((j*3 +k)*4 + l)*4
  104.         mov    bx, 3
  105.         mul    bx        ;j*3
  106.         add    ax, k        ;j*3 + k
  107.         add    ax, ax        ;(j*3 + k)*2
  108.         add    ax, ax        ;(j*3 + k)*4
  109.         add    ax, l        ;(j*3 + k)*4 + l
  110.         add    ax, ax        ;((j*3 + k)*4 + l)*2
  111.         add    ax, ax        ;((j*3 + k)*4 + l)*4
  112.         mov    bx, ax
  113.         mov    PtAry3[bx].X, 0
  114.  
  115. Quit:        mov    ah, 4ch        ;Magic number for DOS
  116.         int    21h        ; to tell this program to quit.
  117. Main        endp
  118. cseg        ends
  119.  
  120. sseg        segment    para stack 'stack'
  121. stk        byte    1024 dup ("stack   ")
  122. sseg        ends
  123.  
  124. zzzzzzseg    segment    para public 'zzzzzz'
  125. LastBytes    byte    16 dup (?)
  126. zzzzzzseg    ends
  127.         end    Main
  128.